/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import static GUI.PainelPrincipal.*;
import easyscore.Jogador;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.WindowConstants;

/**
 *
 * @author Rui Margarido
 */
public class PopUpFaltas extends javax.swing.JFrame {

    int number, equipa, index;
    AtualizaImagemFalta updater;
    /**
     * Creates new form PopUpFaltas
     */
    public PopUpFaltas(int number, int index, int equipa) {
        this.number=number;
        this.index = index;
        this.equipa=equipa;
        initComponents();
        updater = new AtualizaImagemFalta();
        updater.start();
     
    }
/*
    public void iniciaLabels()
    {
        LabelNumeroJogador.setText("#" + number);
        
        if(faltas<=1)
        {
            LabelFaltas1.setIcon(imgVerde);
            if(faltas<=2)
            {
                LabelFaltas2.setIcon(imgVerde);
                if(faltas<=3)
                    {
                        LabelFaltas3.setIcon(imgAmarelo);
                        if(faltas<=4)
                        {
                            LabelFaltas4.setIcon(imgLaranja);
                            if(faltas<=5)
                            {
                                LabelFaltas5.setIcon(imgVermelho);
                            }
                        }
                    }
            }
        }
    }
  */  
    public class AtualizaImagemFalta extends Thread
    {
        Boolean corre = true;
        public void run()
        {
            while(corre)
            {
                try {
                    Thread.sleep(1);
                    update();
                } catch (InterruptedException ex) {
                    System.out.println("Thread do popup falhou em update");
                }
                
            }
        }
    }
    
    public void update()
    {
        int faltas = _Jogo.getFaltasJogador(equipa, index);
        if(faltas>=1)
        {
            LabelFaltas1.setIcon(imgVerde);
            if(faltas>=2)
            {
                LabelFaltas2.setIcon(imgVerde);
                if(faltas>=3)
                {
                    LabelFaltas3.setIcon(imgAmarelo);
                    if(faltas>=4)
                    {
                        LabelFaltas4.setIcon(imgLaranja);
                        if(faltas>=5)
                        {
                            LabelFaltas5.setIcon(imgVermelho);
                        }
                    }
                }
            }
        }
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        LabelEquipa = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        LabelFaltas1 = new javax.swing.JLabel();
        LabelFaltas2 = new javax.swing.JLabel();
        LabelFaltas3 = new javax.swing.JLabel();
        LabelFaltas4 = new javax.swing.JLabel();
        LabelFaltas5 = new javax.swing.JLabel();
        LabelNumeroJogador = new javax.swing.JLabel();
        BotaoConfirmar = new javax.swing.JButton();
        BotaoProximo = new javax.swing.JButton();
        BotaoFaltaDisciplinar = new javax.swing.JButton();
        BotaoFaltaTecnica = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        LabelEquipa.setText("             Equipa 1");

        LabelFaltas1.setMaximumSize(new java.awt.Dimension(38, 40));
        LabelFaltas1.setMinimumSize(new java.awt.Dimension(38, 40));
        LabelFaltas1.setPreferredSize(new java.awt.Dimension(38, 40));

        LabelFaltas4.setMaximumSize(new java.awt.Dimension(38, 40));
        LabelFaltas4.setMinimumSize(new java.awt.Dimension(38, 40));
        LabelFaltas4.setPreferredSize(new java.awt.Dimension(38, 40));

        LabelFaltas5.setMaximumSize(new java.awt.Dimension(34, 40));
        LabelFaltas5.setMinimumSize(new java.awt.Dimension(34, 40));
        LabelFaltas5.setPreferredSize(new java.awt.Dimension(34, 40));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(LabelFaltas1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(LabelFaltas2, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(LabelFaltas3, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(LabelFaltas4, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(LabelFaltas5, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(LabelFaltas1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(LabelFaltas3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(LabelFaltas5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(LabelFaltas4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(LabelFaltas2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        LabelNumeroJogador.setText("    #99");

        BotaoConfirmar.setText("Confirmar");
        BotaoConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotaoConfirmarActionPerformed(evt);
            }
        });

        BotaoProximo.setText("Próximo");

        BotaoFaltaDisciplinar.setText("Falta Disciplinar");
        BotaoFaltaDisciplinar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotaoFaltaDisciplinarActionPerformed(evt);
            }
        });

        BotaoFaltaTecnica.setText("Falta Tecnica");
        BotaoFaltaTecnica.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotaoFaltaTecnicaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(LabelNumeroJogador, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(BotaoProximo, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(BotaoConfirmar, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(BotaoFaltaTecnica, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(BotaoFaltaDisciplinar, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(89, 89, 89)
                .addComponent(LabelEquipa, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(LabelEquipa, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LabelNumeroJogador, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(BotaoFaltaDisciplinar, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                    .addComponent(BotaoFaltaTecnica, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BotaoConfirmar, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BotaoProximo, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BotaoFaltaTecnicaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotaoFaltaTecnicaActionPerformed
        _Jogo.adicionarFalta(equipa, number, _Jogo.getTempoSeg(), Jogador.TipoFalta.Tecnica);
    }//GEN-LAST:event_BotaoFaltaTecnicaActionPerformed

    private void BotaoFaltaDisciplinarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotaoFaltaDisciplinarActionPerformed
        _Jogo.adicionarFalta(equipa, number, _Jogo.getTempoSeg(), Jogador.TipoFalta.AntiDesportiva);
    }//GEN-LAST:event_BotaoFaltaDisciplinarActionPerformed

    private void BotaoConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotaoConfirmarActionPerformed
        updater.corre=false; //Cansou (つ°ヮ°)つ
        this.dispose();
    }//GEN-LAST:event_BotaoConfirmarActionPerformed

    /**
     * @param args the command line arguments
     */
    
//    public static void main(String args[]) {
//        /* Set the Nimbus look and feel */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
//         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(PopUpFaltas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(PopUpFaltas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(PopUpFaltas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(PopUpFaltas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /* Create and display the form */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new PopUpFaltas(1,1,1).setVisible(true);
//            }
//        });
//    }
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BotaoConfirmar;
    private javax.swing.JButton BotaoFaltaDisciplinar;
    private javax.swing.JButton BotaoFaltaTecnica;
    private javax.swing.JButton BotaoProximo;
    private javax.swing.JLabel LabelEquipa;
    private javax.swing.JLabel LabelFaltas1;
    private javax.swing.JLabel LabelFaltas2;
    private javax.swing.JLabel LabelFaltas3;
    private javax.swing.JLabel LabelFaltas4;
    private javax.swing.JLabel LabelFaltas5;
    private javax.swing.JLabel LabelNumeroJogador;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
